package spem.activity.diagram.part;

import java.util.Collections;
import java.util.List;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
import org.eclipse.gef.palette.PaletteStack;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

import spem.activity.diagram.providers.SpemElementTypes;

/**
 * @generated
 */
public class SpemPaletteFactory {

	/**
	 * @generated
	 */
	public void fillPalette(PaletteRoot paletteRoot) {
		paletteRoot.add(createNode1Group());
		paletteRoot.add(createLink2Group());
	}

	/**
	 * Creates "node" palette tool group
	 * @generated
	 */
	private PaletteContainer createNode1Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.Node1Group_title);
		paletteContainer.setId("createNode1Group"); //$NON-NLS-1$
		paletteContainer.add(createActivity1CreationTool());
		paletteContainer.add(createWorkProductDefinition2CreationTool());
		paletteContainer.add(createTaskDefinition3CreationTool());
		paletteContainer.add(createRoleDefinition4CreationTool());
		paletteContainer.add(createDecision5CreationTool());
		paletteContainer.add(createTool6CreationTool());
		paletteContainer.add(new PaletteSeparator());
		paletteContainer.add(createStep8CreationTool());
		return paletteContainer;
	}

	/**
	 * Creates "link" palette tool group
	 * @generated
	 */
	private PaletteContainer createLink2Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.Link2Group_title);
		paletteContainer.setId("createLink2Group"); //$NON-NLS-1$
		paletteContainer.add(createUse1CreationTool());
		paletteContainer.add(createPerforms2CreationTool());
		paletteContainer.add(createControlFlow3CreationTool());
		paletteContainer.add(createWt4Group());
		return paletteContainer;
	}

	/**
	 * Creates "wt" palette tool group
	 * @generated
	 */
	private PaletteContainer createWt4Group() {
		PaletteStack paletteContainer = new PaletteStack(
				Messages.Wt4Group_title, null, null);
		paletteContainer.setId("createWt4Group"); //$NON-NLS-1$
		paletteContainer.add(createOutput1CreationTool());
		paletteContainer.add(createInput2CreationTool());
		return paletteContainer;
	}

	/**
	 * @generated
	 */
	private ToolEntry createActivity1CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Activity1CreationTool_title,
				Messages.Activity1CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Activity_2003));
		entry.setId("createActivity1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Activity_2003));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createWorkProductDefinition2CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.WorkProductDefinition2CreationTool_title,
				Messages.WorkProductDefinition2CreationTool_desc,
				Collections
						.singletonList(SpemElementTypes.WorkProductDefinition_2001));
		entry.setId("createWorkProductDefinition2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.WorkProductDefinition_2001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createTaskDefinition3CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.TaskDefinition3CreationTool_title,
				Messages.TaskDefinition3CreationTool_desc,
				Collections.singletonList(SpemElementTypes.TaskDefinition_2005));
		entry.setId("createTaskDefinition3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.TaskDefinition_2005));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createRoleDefinition4CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.RoleDefinition4CreationTool_title,
				Messages.RoleDefinition4CreationTool_desc,
				Collections.singletonList(SpemElementTypes.RoleDefinition_2002));
		entry.setId("createRoleDefinition4CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.RoleDefinition_2002));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createDecision5CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Decision5CreationTool_title,
				Messages.Decision5CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Decision_2004));
		entry.setId("createDecision5CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Decision_2004));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createTool6CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Tool6CreationTool_title,
				Messages.Tool6CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Tool_2006));
		entry.setId("createTool6CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Tool_2006));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createStep8CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Step8CreationTool_title,
				Messages.Step8CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Step_3001));
		entry.setId("createStep8CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Step_3001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createUse1CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Use1CreationTool_title,
				Messages.Use1CreationTool_desc,
				Collections
						.singletonList(SpemElementTypes.TaskDefinitionUses_4004));
		entry.setId("createUse1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.TaskDefinitionUses_4004));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createPerforms2CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Performs2CreationTool_title,
				Messages.Performs2CreationTool_desc,
				Collections
						.singletonList(SpemElementTypes.RoleDefinitionPerforms_4002));
		entry.setId("createPerforms2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.RoleDefinitionPerforms_4002));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createControlFlow3CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.ControlFlow3CreationTool_title,
				Messages.ControlFlow3CreationTool_desc,
				Collections.singletonList(SpemElementTypes.ControlFlow_4001));
		entry.setId("createControlFlow3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.ControlFlow_4001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createOutput1CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Output1CreationTool_title,
				Messages.Output1CreationTool_desc,
				Collections
						.singletonList(SpemElementTypes.TaskDefinitionOutput_4005));
		entry.setId("createOutput1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.TaskDefinitionOutput_4005));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createInput2CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Input2CreationTool_title,
				Messages.Input2CreationTool_desc,
				Collections
						.singletonList(SpemElementTypes.TaskDefinitionInput_4003));
		entry.setId("createInput2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.TaskDefinitionInput_4003));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private static class NodeToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> elementTypes;

		/**
		 * @generated
		 */
		private NodeToolEntry(String title, String description,
				List<IElementType> elementTypes) {
			super(title, description, null, null);
			this.elementTypes = elementTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeCreationTool(elementTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}

	/**
	 * @generated
	 */
	private static class LinkToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> relationshipTypes;

		/**
		 * @generated
		 */
		private LinkToolEntry(String title, String description,
				List<IElementType> relationshipTypes) {
			super(title, description, null, null);
			this.relationshipTypes = relationshipTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}
}
